﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
// add
using FormBaseLib;

namespace FormBase
{
    public partial class FPGM0100 : Form
    {

        public FPGM0100()
        {
            InitializeComponent();
        }

        private void FPGM0100_Load(object sender, EventArgs e)
        {
            txtFile.Text = CProject.mFileKeyValue.msFile;
        }

        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            ListView1.HeaderStyle = ColumnHeaderStyle.Clickable;
            ListView1.View = View.Details;
            ListView1.FullRowSelect = true;
            ListView1.Columns.Clear();
            ListView1.Columns.Add("No.");
            ListView1.Columns.Add("Key");
            ListView1.Columns.Add("Value");
            ListView1.Columns[0].Width = 20;
            ListView1.Columns[1].Width = 180;
            ListView1.Columns[2].Width = 300;

            int iNo;
            iNo = 0;
            //foreach (KeyValuePair<string, string> kvp in CProject.mFileKeyValue.mDict)
            //{
            //    //Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
            //    //sa1[i] = kvp.Key;
            //    iNo++;
            //    ListViewItem listItem = new ListViewItem();
            //    listItem.Text = iNo.ToString();
            //    listItem.SubItems.Add(kvp.Key);
            //    listItem.SubItems.Add(kvp.Value);
            //    ListView1.Items.Add(listItem);
            //}
            foreach (CItemKeyValue itemP in CProject.mFileKeyValue)
            {
                iNo++;
                ListViewItem listItem = new ListViewItem();
                listItem.Text = iNo.ToString();
                listItem.SubItems.Add(itemP.msKey);
                listItem.SubItems.Add(itemP.msValue);
                ListView1.Items.Add(listItem);
            }


            //ListViewItem listItem = new ListViewItem();
            //listItem.Text = "";
            //listItem.SubItems.Add("ProductName");
            //listItem.SubItems.Add(AssemblyProduct);
            //listView1.Items.Insert(0, listItem);

            //listItem = new ListViewItem();
            //listItem.Text = "";
            //listItem.SubItems.Add("Version");
            //listItem.SubItems.Add(String.Format("Version {0}", AssemblyVersion));
            //listView1.Items.Insert(1, listItem);

            //listItem = new ListViewItem();
            //listItem.Text = "";
            //listItem.SubItems.Add("Copyright");
            //listItem.SubItems.Add(AssemblyCopyright);
            //listView1.Items.Insert(2, listItem);

            //listItem = new ListViewItem();
            //listItem.Text = "";
            //listItem.SubItems.Add("CompanyName");
            //listItem.SubItems.Add(AssemblyCompany);
            //listView1.Items.Insert(3, listItem);

            //Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
            //int index = 0;
            //foreach (AssemblyName an in asm.GetReferencedAssemblies())
            //{
            //    listItem = new ListViewItem();
            //    listItem.Text = "";
            //    listItem.SubItems.Add(an.Name);
            //    listItem.SubItems.Add(string.Format("{0}", an.Version));
            //    listView2.Items.Insert(index, listItem);

            //    index++;
            //}

        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!CProject.mFileKeyValue.FileSave())
                CProject.mApp.PopupError(CProject.mFileKeyValue.msLastError);

        }

        private void setKeyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //string sKey = string.Empty;
            //string sValue = string.Empty;

            //CProject.mFileKeyValue.SetValue(sKey, sValue);
            //CProject.mFileKeyValue.mRow.msKey = string.Empty;
            //CProject.mFileKeyValue.mRow.msValue = string.Empty;
            //CProject.mFileKeyValue.RowUpdate(true);

            CProject.mFileKeyValue.mRow.Clear();
            CProject.mFileKeyValue.Update();

        }
    }
}
